﻿procedure;
var
  MP_DSOsoby: TAppDataSet;
  MP_SLOsoby: TStringList;
  DS: TAppDataSet;
  id, str, idPer, idEmpl: string;
  dateStartPer, dateEndPer: DateTime;
  
begin
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'6269,5',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'9999,9999',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNonNLP,lttAll,[mtaInsert,mtaUpdate,mtaDelete],[mtaInsert]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNonLicAndNLP,lttNonLangOrNonNLP,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNonNLP,lttLangOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttLicAndNLP,lttNonNLPOnly,[mtaInsert,mtaUpdate,mtaDelete],[]);
  AppServer.SetDSTransferData(SourceName,'165587,10',nttNLPOnly,lttNLPOnly,[mtaIUpdate],[]);
  M17059359_10;  // NEMAZAT, STANDARDNI SOUCAST REINSTALACE
  
  //PM/KK - Prednastaveni konfiguracnich atr. pro komunikaci s datovou schrankou (NESPUSTIT)
  if (AppServer.GetDBAtrValue(SourceName, rmPrimary, MainLang, '15777,10', '42600548,10', '15852,10') = '') then
    AppServer.SetDBAtrValue(SourceName, MainLang, '15777,10', '42600548,10', '15852,10', '3');
  if AppServer.GetDBAtrValue(SourceName, rmPrimary, MainLang, '15777,10', '42600550,10', '15852,10') = '' then
    AppServer.SetDBAtrValue(SourceName, MainLang, '15777,10', '42600550,10', '15852,10', '1'); 
  
  // MP - Naplnění nové podřízené datové třídy  "Osoba - Obchodní partner" (42570022,10)    - SPUSTIT
  MP_DSOsoby := TAppDataSet.Create;
  MP_SLOsoby := TStringList.Create;
  try
    MP_DSOsoby.SetDSParams(SourceName, rmPrimary, '471944,10', dsaReadNonVisible);
    MP_DSOsoby.SpecWhere := '471945,10.156,0'; // najít osoby, které jsou zároveň v Obchodních partnerech
    MP_DSOsoby.Open;
    while not MP_DSOsoby.EOF do
    begin
      if not AppServer.ExistDBkeyValue(SourceName, rmPrimary, '42570022,10', MP_DSOsoby.GetPKValue) then
      begin
        MP_SLOsoby.Clear;
        MP_SLOsoby.Values['ic'] := MP_DSOsoby.FieldByName('ic').AsString;
        MP_SLOsoby.Values['u'] := MP_DSOsoby.FieldByName('u').AsString;
        AppServer.InsertDBRecord(SourceName, '', '42570022,10', True, MP_SLOsoby);        
      end;        
      MP_DSOsoby.Next;
    end; 
  finally
    MP_DSOsoby.Free;
    MP_SLOsoby.Free;
  end;
  // MP End
  
  // ZS - Cizinci - naplneni udaje "Prislusnost k cizim statnim predpisum (NESPOUSTET)
  if (Legislation = '745998,10') then
  begin
    DS := TAppDataSet.Create;
    try
      // DS Cizi statni prislusnik
      DS.SetDSParams(SourceName, rmPrimary, '2522305,10', dsaViewNonVisible);
      DS.NoMacros := true;
      DS.Open;
      while not DS.EOF do
      begin
        if not DS.FieldByName('2522337,10').IsNull then
        begin
          // je vyplnena SP, ma prislusnost k cizim statnim predpisum
          AppServer.SetDBAtrValue(SourceName,'', '2519000,10', '42612758,10', DS.GetPKValue, '1');
          // statni prislusnost
          id := AppServer.GetDBKeyValue(SourceName, rmPrimary, '2523180,10', DS.GetPKValue, ftIDA, ftIDB);
          if (id <> '') then
          begin
            str := AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '3107,10', '819516,10', id);
            if (str <> '') then
              AppServer.SetDBAtrValue(SourceName, '', '2519000,10', '42612760,10', DS.GetPKValue, str);
          end;
        end else
          AppServer.SetDBAtrValue(SourceName,'', '2519000,10', '42612758,10', DS.GetPKValue, '0');
        
        DS.Next;  // dalsi cizi statni prislusnik
      end;
    finally
      DS.Free;
    end;
    id := '';
    str := '';
  end;
  // ZS konec
  
  // ZS - prenos hesla od PPV k zamestnanci (NESPOUSTET)
  if (Legislation = '745998,10') then
  begin
    idPer := AppServer.GetDBKeyValues(SourceName, rmPrimary, '450391,10', '"451082,10" = 0');
    if (idPer <> '') then
    begin
      dateStartPer := ANSIStrToDate(AppServer.GetDBAtrValue(SourceName, rmPrimary, '', '450391,10', '546181,10', idPer));
      dateEndPer := DateAdd(dpDay, -1, DateAdd(dpMonth, 1, dateStartPer));
      
      DS := TAppDataSet.Create;
      try
        // DS PPV k VO
        // 1. aktivni PPV
        // 2. vyplneno heslo
        DS.SetDSParams(SourceName, rmPrimary, '448543,10', dsaViewNonVisible, '', '', '',
                       Format('("1100994,10" <= ''%%'') AND (("455434,10" >= ''%%'') OR "455434,10" IS NULL) AND "7816689,10" IS NOT NULL',
                              [DateToANSIStr(dateEndPer), DateToANSIStr(dateStartPer)]),
                       '"ic_a", "u_a" ASC');
        DS.NoMacros := true;
        DS.Open;
        if not DS.IsEmpty then
        begin
          while not DS.EOF do
          begin
            if (idEmpl <> DS.GetKeyValue('', ftIDA)) then
            begin
              // zapis hesla k zamestnanci (od prvniho PPV zamestnance)
              AppServer.SetDBAtrBinValue(SourceName, '', '150,0', '42427265,10', DS.GetKeyValue('', ftIDA),
                                         AppServer.GetDBAtrBinValue(SourceName, rmPrimary, '', '446925,10', '7816685,10', DS.GetPKValue));
              idEmpl := DS.GetKeyValue('', ftIDA);
            end;
            
            DS.Next;  // dalsi zaznam
          end;
        end;
      finally
        DS.Free;
      end;
    end;
  end;
  // ZS konec  
end.